package com.weiyi.servlet02;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * 
 * @description 打印报头信息
 * @author 惟一
 * @date 2020年6月26日下午6:00:12
 */
@WebServlet("/header.view")
public class HeaderDemo extends HttpServlet{

	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=UTF-8");
		PrintWriter out = resp.getWriter();
		
		out.println("<html>");
		out.println("<head>");
		out.println("<title>HeaderServlet</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h1>HeaderServlet at"+req.getContextPath()+"</h1>");
		Enumeration<String> headerNames = req.getHeaderNames();
		while(headerNames.nextElement()!=null) {
			String name = headerNames.nextElement();
			out.println(name+ ":" + req.getHeader(name)+"</br>");
		}
		out.println("</body>");
		out.println("</html>");
		
		out.close();
	}
}
